import 'package:flutter/material.dart';


/// 由父控件控制状态
class SampleStateFullWidget extends StatefulWidget {
  const SampleStateFullWidget({Key? key}) : super(key: key);

  @override
  _SampleStateFullWidgetState createState() => _SampleStateFullWidgetState();
}

class _SampleStateFullWidgetState extends State<SampleStateFullWidget> {
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("StatefulWidget示例"),
      ),
      body: CounterWiget(count),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            count++;
          });
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

class CounterWiget extends StatelessWidget {
  final int count;

  const CounterWiget(this.count, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Chip(
        label: Text("$count"),
      ),
    );
  }
}
